﻿using System;
using System.Configuration;

namespace Catalyst.Caching
{
	public class ServerElementCollection : ConfigurationElementCollection
	{
		public ServerElement this[int index]
		{
			get
			{
				return (ServerElement)BaseGet(index);
			}
			set
			{
				if (BaseGet(index) != null)
				{
					BaseRemoveAt(index);
				}

				BaseAdd(index, value);
			}
		}

		protected override ConfigurationElement CreateNewElement()
		{
			return new ServerElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((ServerElement)element).Address;
		}
	}

	public class ServerElement : ConfigurationElement
	{
		[ConfigurationProperty("address", IsRequired = true)]
		public string Address
		{
			get { return this["address"].ToString(); }
		}

		[ConfigurationProperty("port", DefaultValue = 11211, IsRequired = false)]
		public int Port
		{
			get { return (int)this["port"]; }
		}
	}
}
